package com.up4years.dataapi.service.system;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.up4years.dataapi.dao.base.PageDao;
import com.up4years.dataapi.dao.system.EmployeeMapper;
import com.up4years.dataapi.dao.system.UserMapper;
import com.up4years.dataapi.entity.base.Page;
  
@Service
public class EmployeeService {
	@Autowired
	private EmployeeMapper employeeMapper;
	@Autowired
	private PageDao pageQueryDao;
	@Autowired
	private UserMapper userMapper;
	
	public Map<String,Object> getByPhone(String phone){
		return this.employeeMapper.getByPhone(phone);
	}
	public Map<String,Object> getByUserName(String userName){
		return this.employeeMapper.getByUserName(userName);
	}
	public boolean existUserName(String username){
		return this.employeeMapper.existUserName(username)>0;
	}
	public boolean existPhone(String mobile){
		return this.employeeMapper.existPhone(mobile)>0;
	}
	public List<Map<String,Object>> list(Map<String,Object> parameters){
		return this.employeeMapper.list(parameters);
	}
	public Page<Map<String,Object>> pageList(Page<Map<String,Object>> page,Object parameters){
		String statementName = "com.up4years.dataapi.dao.system.EmployeeMapper.list";
		return this.pageQueryDao.pageQuery(page, statementName, parameters);
 	}
	public boolean contract(String user_id){
		return this.employeeMapper.contract(user_id)==1;
	}
	public boolean discontract(String user_id){
		return this.employeeMapper.discontract(user_id)==1;
	}
	public boolean reset(String user_id){
		return this.employeeMapper.reset(user_id)==1;
	}
	/**
	 * 创建用户
	 * @param map
	 * @return id
	 */
	@Transactional
	public long create(Map<String,Object> map){
		this.employeeMapper.create(map);
		long user_id = (Long) map.get("id");
		return user_id;
	}
	/**
	 * 生成工号
	 * @return
	 */
	public String generateEmployeeCode(){
		Date date = new Date();
		String code = "" +date.getTime();
		return code;
	}
}
